#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    int dx[4]={0,0,-1,1};
    int dy[4]={-1,1,0,0};
    cin>>n>>m;
    vector<vector<int>> arr(n,vector<int>(m,0));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin>>arr[i][j];

    for (int j = 0; j < m; ++j)
        cout<<arr[0][j]<<' ';
    cout<<endl;
    for (int i = 1; i < n - 1; ++i) {
        cout<<arr[i][0]<<' ';
        for (int j = 1, tmp; j < m - 1; ++j) {
            tmp = arr[i][j];
            for (int k = 0; k < 4; ++k)
                tmp += arr[i+dx[k]][j+dy[k]];
            cout << int(tmp / 5.0 + 0.5) << ' ';
        }
        cout<<arr[i][m-1]<<endl;
    }
    for (int j = 0; j < m; ++j)
        cout<<arr[n-1][j]<<' ';
    cout<<endl;
    return 0;
}